package assignments.sagarjoshi.springtms;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

/**
 * Created by sagar.joshi on 21/1/15.
 */
public class AllocationAdapter extends ArrayAdapter<AllocationItemClass>
{
    AllocationItemClass[] data;
    Context context;
    public AllocationAdapter(Context context,AllocationItemClass[] data)
    {
        super(context,R.layout.allocationlistitem,data);
        this.data=data;
        this.context=context;
    }

    public View getView(int pos,View v,ViewGroup parent)
    {
       v= ((LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.allocationlistitem,null);
        ((TextView)v.findViewById(R.id.alloc_idval)).setText(data[pos].Trainee_id);
        ((TextView)v.findViewById(R.id.alloc_nameval)).setText(data[pos].Trainee_name);
        String stat_text=data[pos].status;
       /* if(stat_text.isEmpty())
        {
            ((CheckBox)v.findViewById(R.id.chk_alloc)).setChecked(false);
        }*/
        if(!stat_text.isEmpty())
        {
           // ((CheckBox)v.findViewById(R.id.chk_alloc)).setChecked(true);
            ((TextView)v.findViewById(R.id.alloc_dateval)).setText(data[pos].allocation_date);
            TextView status=(TextView)v.findViewById(R.id.alloc_status);

            status.setVisibility(View.VISIBLE);
            status.setText(data[pos].status);
            if(stat_text.equals("rejected"))
            {
                status.setText(stat_text+" : Reason -  "+data[pos].comments );
                status.setTextColor(context.getResources().getColor(android.R.color.holo_red_dark));
            }
            else if(stat_text.equals("confirmed"))
            {
                status.setTextColor(context.getResources().getColor(android.R.color.holo_green_dark));
            }
            else if(stat_text.equals("allocated"))
            {
                status.setTextColor(context.getResources().getColor(android.R.color.holo_blue_dark));
            }

        }

        return  v;
    }
}
